package TwoPointers;

public class _838_PushDominoes {
    public String pushDominoes(String dominoes) {
        int N = dominoes.length();
        int[] notation = new int[N];
        int priori = 0;
        for (int i = 0; i < dominoes.length(); i++) {
            char c = dominoes.charAt(i);
            if (c == 'R') {
                priori = N;
            } else if (c == 'L') {
                priori = 0;
            } else {
                priori = Math.max(priori - 1, 0);
            }
            notation[i] += priori;
        }
        priori = 0;
        for (int i = N - 1; i >= 0; i--) {
            char c = dominoes.charAt(i);
            if (c == 'L') {
                priori =  N;
            } else if (c == 'R') {
                priori = 0;
            } else {
                priori = Math.max(priori - 1, 0);
            }
            notation[i] -= priori;
        }
        StringBuffer sb = new StringBuffer();
        for (int p : notation) {
            sb.append(p > 0 ? 'R' : p < 0 ? 'L' : '.');
        }
        return sb.toString();
    }

}
